package com.yingside.collection.homework;

import java.util.*;

public class Test5 {
    public static void main(String[] args) {
        Student s1 = new Student("zhangsan",24,90);
        Student s2 = new Student("lisi",22,90);
        Student s3 = new Student("wangwu",21,100);
        Student s4 = new Student("zhaoliu",25,90);

        /*Set<Student> sets = new TreeSet<>();
        sets.add(s1);
        sets.add(s2);
        sets.add(s3);
        sets.add(s4);

        for (Student student:sets) {
            System.out.println("student = " + student);
        }*/

        List<Student> list = new ArrayList<>();
        list.add(s1);
        list.add(s2);
        list.add(s3);
        list.add(s4);

        Collections.sort(list, new Comparator<Student>() {
            public int compare(Student stu1, Student stu2) {
                float diff = stu1.getScore() - stu2.getScore();
                if (diff > 0){
                    return 1;
                }
                else if(diff < 0){
                    return -1;
                }
                else{
                    int d = stu1.getAge() - stu2.getAge();
                    return d;
                }
            }
        });

        for (Student student:list) {
            System.out.println("student = " + student);
        }

    }
}
